package com.hibiscusking.basic.controller;

import com.hibiscusking.basic.dto.AccountLoginDto;
import com.hibiscusking.basic.dto.EmailAccountLoginDto;
import com.hibiscusking.basic.dto.WechatLoginDto;
import com.hibiscusking.basic.dto.WechatPhoneBinderDto;
import com.hibiscusking.basic.service.LoginService;
import com.hibiscusking.basic.util.AjaxResult;
import com.hibiscusking.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping("/account")
    public AjaxResult loginAccount(@RequestBody @Valid AccountLoginDto dto) {
        Map<String,Object> loginMap= loginService.loginAccount(dto);
        return AjaxResult.me().success(loginMap);
    }
    @PostMapping("/emailAccount")
    public AjaxResult emailLoginAccount(@RequestBody @Valid EmailAccountLoginDto dto) {
        Map<String,Object> loginMap= loginService.emailLoginAccount(dto);
        return AjaxResult.me().success(loginMap);
    }
    @PostMapping("/wechat")
    public AjaxResult wechatAccountLogin(@RequestBody @Valid WechatLoginDto dto) {
        return loginService.WeChatLogin(dto);
    }
    @PostMapping("/wechat/binder")
    public AjaxResult wechatPhoneBinder(@RequestBody @Valid WechatPhoneBinderDto dto) {
        Map<String, Object> map= loginService.wechatPhoneBinder(dto);
        return AjaxResult.me().success(map);
    }
}
